package com.lemeng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lemeng.service.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

@RestController
@RequestMapping("pay")
public class PayController {
    @Reference
    OrderService orderService;

    @RequestMapping("notify")
    public void paynotify(HttpServletRequest request)throws Exception{
        System.out.println("请求成功了  宝贝");
        InputStream inputStream = request.getInputStream();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bytes = new byte[1024];

        int len = 0;
        while ((len=inputStream.read(bytes))!=-1){
            byteArrayOutputStream.write(bytes,0,len);
        }

        inputStream.close();
        byteArrayOutputStream.close();

        //微信回调参数的字符串;xml格式的
        String str = new String(byteArrayOutputStream.toByteArray(), "utf-8");

        orderService.wxPaySuccess(str);


    }

}
